package com.demo.oauth.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.demo.oauth.server.model.ApplicationClient;
import com.demo.oauth.server.model.AuthenticationCode;
import com.demo.oauth.server.service.ApplicationClientService;
import com.demo.oauth.server.service.AuthenticationCodeService;

@RestController
public class DemoClientController {

	@Autowired
	private ApplicationClientService demoClientService;

	@Autowired
	private AuthenticationCodeService authenticationCodeService;

	@GetMapping("/demo/{clientId}")
	public String getClientById(@PathVariable("clientId") String clientId) {
		ApplicationClient client = demoClientService.selectById(clientId);
		return client.getName();

	}

	@GetMapping("/demo/code")
	public String savecode() {
		AuthenticationCode code = new AuthenticationCode();
		code.setCode("110");
		code.setUserId("1234");
		code.setClientId("1234");
		authenticationCodeService.insert(code);
		return code.getCode();
	}

}
